/**
 * MenuFrameBase.java
 *
 * Roslan's Remake of MOO in 3D using Ardor3D
 * (C) 2011 Roslan Amir. All rights reserved.
 */

package com.roslan.games.moo3d.ui.menu;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ardor3d.extension.ui.UIFrame;
import com.ardor3d.extension.ui.UIFrameBar;
import com.ardor3d.extension.ui.UIPanel;
import com.ardor3d.extension.ui.backdrop.SolidBackdrop;
import com.ardor3d.extension.ui.border.SolidBorder;
import com.ardor3d.extension.ui.border.UIBorder;
import com.ardor3d.extension.ui.layout.RowLayout;
import com.ardor3d.extension.ui.util.Insets;
import com.ardor3d.extension.ui.util.SubTex;
import com.ardor3d.image.Texture;
import com.ardor3d.util.TextureManager;
import com.roslan.games.moo3d.Base;
import com.roslan.games.moo3d.GameData;
import com.roslan.games.moo3d.Main;
import com.roslan.games.moo3d.data.Race;
import com.roslan.games.moo3d.ui.hud.HudManager;

/**
 * The superclass for all menu frames.
 * 
 * @author Roslan Amir
 * @version 1.0 - Jan 27, 2011
 */
public abstract class MenuFrameBase extends UIFrame {

	/**
     * 
     */
	protected static final Logger logger = LoggerFactory.getLogger(Base.class);

	/**
	 * 
	 */
	protected static final Insets MARGINS = new Insets(4, 4, 0, 4);

	/**
	 * 
	 */
	protected static final Insets PADDING = new Insets();

	/**
	 * 
	 */
	protected static final Insets FRAME_MARGINS = new Insets(4, 0, 4, 0);

	/**
	 * 
	 */
	protected static final UIBorder SOLID_BORDER = new SolidBorder(4, 4, 4, 4);

	/**
	 * 
	 */
	protected static final String IMAGES_MAIN_MENU_BUTTONS = "images/mainmenu_buttons.png";

	/**
	 * 
	 */
	protected static final String IMAGES_NEW_GAME_CHOOSE_RACE_HEADS = "images/new_game_choose_race_heads.png";

	/**
	 * 
	 */
	protected static final String IMAGES_NEW_GAME_CHOOSE_RACE_DESC = "images/new_game_choose_race_desc.png";

	/**
	 * 
	 */
	protected static final String IMAGES_NEW_GAME_CHOOSE_BANNER_FLAGS = "images/new_game_choose_banner_flags_border.png";

	/**
	 * 
	 */
	protected static final SubTex[] SUBTEX_MAIN_MENU_BUTTONS = new SubTex[5];

	/**
	 * 
	 */
	protected static final SubTex[] SUBTEX_RACE_HEADS = new SubTex[Race.TOTAL_NO_OF_RACES];

	/**
	 * 
	 */
	protected static final SubTex[] SUBTEX_RACE_DESCS = new SubTex[Race.TOTAL_NO_OF_RACES];

	/**
	 * 
	 */
	protected static final SubTex[] SUBTEX_BANNERS = new SubTex[GameData.TOTAL_NO_OF_BANNERS];

	/*
	 * Load the image textures.
	 */
	static {
		/*
		 * Load the main menu image textures.
		 */
		final Texture tex1 = TextureManager.load(IMAGES_MAIN_MENU_BUTTONS, Texture.MinificationFilter.Trilinear, false);
		for (int i = 0; i < SUBTEX_MAIN_MENU_BUTTONS.length; i++) {
			SUBTEX_MAIN_MENU_BUTTONS[i] = new SubTex(tex1, 0, i * 40, 256, 40);
		}

		/*
		 * Load the Race head image textures.
		 */
		final Texture tex2 = TextureManager.load(IMAGES_NEW_GAME_CHOOSE_RACE_HEADS, Texture.MinificationFilter.Trilinear, false);
		for (int i = 0; i < SUBTEX_RACE_HEADS.length; i++) {
			SUBTEX_RACE_HEADS[i] = new SubTex(tex2, i * 288, 0, 288, 320);
		}

		/*
		 * Load the Race desc image textures.
		 */
		final Texture tex3 = TextureManager.load(IMAGES_NEW_GAME_CHOOSE_RACE_DESC, Texture.MinificationFilter.Trilinear, false);
		for (int i = 0; i < SUBTEX_RACE_DESCS.length; i++) {
			SUBTEX_RACE_DESCS[i] = new SubTex(tex3, 0, i * 122, 288, 122);
		}

		/*
		 * Load the FleetBanner image textures.
		 */
		final Texture tex4 = TextureManager.load(IMAGES_NEW_GAME_CHOOSE_BANNER_FLAGS, Texture.MinificationFilter.Trilinear, false);
		for (int i = 0; i < SUBTEX_BANNERS.length; i++) {
			SUBTEX_BANNERS[i] = new SubTex(tex4, i * 97, 0, 97, 112);
		}
	}

	/**
	 * 
	 */
	protected final GameData gameData = GameData.getInstance();

	/**
	 * The main menu panel.
	 */
	protected final UIPanel vpanel;

	/**
	 * Default no-arg constructor.
	 * 
	 * @param title
	 */
	protected MenuFrameBase(String title) {
		super(title);

		/*
		 * Panel with a vertical layout
		 */
		vpanel = new UIPanel();
		vpanel.setLayout(new RowLayout(false));
	}

	/**
	 * Comment for method.
	 */
	protected void setUpFrame() {
		final SolidBackdrop backDrop = new SolidBackdrop(GameData.COLOR_CHOCOLATE);
		this.setBackdrop(backDrop);

		final UIFrameBar titleBar = this.getTitleBar();
		titleBar.setFontStyles(HudManager.FONT_STYLES);
		titleBar.setMargin(HudManager.FRAME_INSETS);

		this.updateMinimumSizeFromContents();
		this.layout();
		this.pack();
		this.setUseStandin(true);
		this.setOpacity(0.9f);
		this.setLocationRelativeTo(Main.camera);
	}

}
